<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 5/10/24
 * Time: 11:13 AM
 */

namespace app\adminapi\logic\shield;


use app\common\logic\BaseLogic;
use app\common\model\shield\BlackCity;

class BlackCityLogic extends BaseLogic
{

    /**
     * 新增
     *
     * @param $params
     * @return bool|int
     */
    public static function save($params)
    {
        $id       = $params['id'] ?? '';
        $platform = $params['platform'] ?? 0;
        $city     = $params['city'];

        if (strpos($city, ',') !== false) {
            $cityArr = explode(',', $city);
        } else {
            $cityArr = explode('，', $city);
        }

        $cityJ = json_encode($cityArr, JSON_UNESCAPED_UNICODE);

        $blackCity = $id ? BlackCity::where('id', $id)->findOrEmpty() : new BlackCity();

        $blackCity->platform = $platform;
        $blackCity->city     = $cityJ;

        return $blackCity->save();
    }


    /**
     * 删除
     *
     * @return bool
     */
    public static function delete($id)
    {
        return BlackCity::destroy($id);
    }
}
